<?php
/**
 * 获取每日病程记录
 * @authors xiadx (xiadx@zpdchina.com)
 * @date    2017-03-07 15:27:51
 * @version $Id$
 */

class GetOneBingchengJiluDataController extends Yaf_Controller_Abstract {

    public function indexAction()
    {
    	$id = $this->getRequest()->getPost('id', "");
        $yiyuan_id = $this->getRequest()->getPost('yiyuan_id', "");
        if($yiyuan_id === "" ){
            Utility::apiJsonError(20028, '请输入医院ID');
        }elseif(!ctype_digit("$yiyuan_id")){
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }

        if($id === "" ){
            Utility::apiJsonError(20028, 'ID为空');
        }

    	$compression_http_data = $this->getRequest()->getPost('compression_http_data', 'off');

        $query = DB::select("doctor_name,record_time,bingcheng_sub_leibie,content")
            ->from("zhuyuan_bingchengjilu");
        if(Yaconf::get("config$yiyuan_id.bingcheng_jilu_xianshi") == "v2")
        {
            $query->where("bingcheng_id","=",$id);
        }else
        {
            $query->where("id","=",$id);
        }
        $res = $query->order_by("doctor_name,record_time,bingcheng_sub_leibie")
        ->execute()
        ->as_array();

        $query_res = array();
		if ($res) {
            $query_res["bingcheng_sub_leibie"] = $res[0]['bingcheng_sub_leibie'];
            $query_res["doctor_name"] = $res[0]['doctor_name'];
            $query_res["record_time"] = $res[0]['record_time'];
            $query_res["content"] = "";
            foreach ($res as $key=>$item)
            {
                $query_res['content'] .= $item['content'];
            }
            $query_res["content"] = strip_tags($query_res["content"]);
            $query_res["content"] = trim($query_res["content"]);
            $query_res["content"] = str_replace("&nbsp;", " ", $query_res["content"]);
            $query_res["bingcheng_sub_leibie"] = trim($query_res["bingcheng_sub_leibie"]);
		}

		$result['result'] = $query_res;
        $result["state"] = empty($query_res)?'0':'1';
        $result['error'] = 200;
        $result['msg'] = '';
		Utility::apiJsonResultExtends($result);
    }
}
